import {
  queryTableList,
  queryColumnList,
  queryDbNameList,
  queryTableNameList,
  queryNameList,
} from '@/services/sensitiveData/infoShow';

export default {
  namespace: 'infoShow',
  state: {
    // 列表数据
    dataqueryTableList: {
      dataList: [],
    },
    dataqueryColumnList: {
      dataList: [],
    },
    dataqueryDbNameList: [],
    dataqueryTableNameList: [],
    dataqueryNameList: [],
  },

  effects: {
    *queryTableList({ payload }, { call, put }) {
      const response = yield call(queryTableList, payload);
      yield put({
        type: 'savequeryTableList',
        payload: response.data || {
          dataList: [],
        },
      });
    },

    *queryColumnList({ payload }, { call, put }) {
      const response = yield call(queryColumnList, payload);
      yield put({
        type: 'savequeryColumnList',
        payload: response.data || {
          dataList: [],
        },
      });
    },
    *queryDbNameList({ payload }, { call, put }) {
      const response = yield call(queryDbNameList, payload);
      yield put({
        type: 'savequeryDbNameList',
        payload: response.data ? response.data.dataList || [] : [],
      });
    },
    *queryTableNameList({ payload }, { call, put }) {
      const response = yield call(queryTableNameList, payload);
      yield put({
        type: 'savequeryTableNameList',
        payload: response.data ? response.data.dataList || [] : [],
      });
    },
    *queryNameList({ payload }, { call, put }) {
      const response = yield call(queryNameList, payload);
      yield put({
        type: 'savequeryNameList',
        payload: response.data ? response.data.dataList || [] : [],
      });
    },
  },

  reducers: {
    savequeryTableList(state, { payload }) {
      return {
        ...state,
        dataqueryTableList: payload,
      };
    },

    savequeryColumnList(state, { payload }) {
      return {
        ...state,
        dataqueryColumnList: payload,
      };
    },
    savequeryDbNameList(state, { payload }) {
      return {
        ...state,
        dataqueryDbNameList: payload,
      };
    },
    savequeryTableNameList(state, { payload }) {
      return {
        ...state,
        dataqueryTableNameList: payload,
      };
    },
    savequeryNameList(state, { payload }) {
      return {
        ...state,
        dataqueryNameList: payload,
      };
    },
  },
};
